#pragma once

#include "ColligereDatabaseInterfaceBase.hpp"

namespace col 
{

////////////////////////////////////////////
// ColligereDataExporterError
////////////////////////////////////////////

class DataExporterError : public std::exception
{
public:
	DataExporterError ( const wxString &rInFile, 
		const wxString &rErrMsg ) : mInFile ( rInFile ), mErrMsg ( rErrMsg ) { }

	virtual ~DataExporterError() { }

	const char *what() const
	{
		static wxString msg;

		msg = boost::str ( boost::format ( _("An error occurred "\
			"while exporting: %1%\n\nFile: %2%") ) % mErrMsg % mInFile );

		return msg.c_str();
	}
private:
	const wxString mInFile, mErrMsg;
};

////////////////////////////////////////////
// ColligereDataExporterBase
////////////////////////////////////////////

class DataExporterBase
{
public:
	virtual ~DataExporterBase() { }
	virtual void Export ( DatabaseInterfaceBase &rFrom,
		const wxString &rToFile ) = 0;
	virtual wxUint32 GetItemCount() const = 0;
};

////////////////////////////////////////////
// ColligereDataExporterEvent
////////////////////////////////////////////

class DataExporterEvent : public wxEvent
{
public:
	DataExporterEvent ( wxEventType commandType, const DataExporterBase *pExporter,
		const DatabaseItemBase *pItem = 0 )  : wxEvent ( wxID_ANY, commandType ), 
		mpExporter ( pExporter ), mpItem ( pItem ) 
	{
		m_propagationLevel = wxEVENT_PROPAGATE_MAX;
	}

	wxEvent *Clone() const { return ( new DataExporterEvent ( *this ) ); }

	const DataExporterBase *GetExporter() const { return mpExporter; }
	const DatabaseItemBase *GetItem() const { return mpItem; }
private:
	const DataExporterBase *mpExporter;
	const DatabaseItemBase *mpItem;
};

typedef void ( wxEvtHandler::*DataExporterEventFunction )( DataExporterEvent & );

}

#define ColligereDataExporterEventHandlerFunction (wxObjectEventFunction) \
	( wxEventFunction )( col::DataExporterEventFunction )

DECLARE_EVENT_TYPE ( COLLIGERE_EVT_EXPORT_START, -1 )
DECLARE_EVENT_TYPE ( COLLIGERE_EVT_EXPORT_END, -1 )
DECLARE_EVENT_TYPE ( COLLIGERE_EVT_ITEM_EXPORTED, -1 )

#define EVT_EXPORT_START (id, fn) DECLARE_EVENT_TABLE_ENTRY( \
        COLLIGERE_EVT_EXPORT_START, id, -1, \
		ColligereDataExporterEventFunction & fn, \
        ( wxObject * ) NULL ), 

#define EVT_EXPORT_END (id, fn) DECLARE_EVENT_TABLE_ENTRY( \
        COLLIGERE_EVT_EXPORT_END, id, -1, \
		ColligereDataExporterEventFunction & fn, \
        ( wxObject * ) NULL ), 

#define EVT_ITEM_EXPORTED (id, fn) DECLARE_EVENT_TABLE_ENTRY( \
        COLLIGERE_EVT_ITEM_EXPORTED, id, -1, \
		ColligereDataExporterEventFunction & fn, \
        ( wxObject * ) NULL ), 